﻿#include "LineEdit_ThermostatRate.h"

#include <qregexp.h>
#include <qvalidator.h>

LineEdit_ThermostatRate::LineEdit_ThermostatRate(QWidget* parent)
  : QLineEdit(parent)
{
  QRegExp regExp("^(\\d+)(\\.\\d+)?$");
  setValidator(new QRegExpValidator(regExp, this));
  connect(this, &LineEdit_ThermostatRate::editingFinished, this, &LineEdit_ThermostatRate::slot_thermostatRateLineEditFinished);
}

LineEdit_ThermostatRate::~LineEdit_ThermostatRate()
{
}
float LineEdit_ThermostatRate::getRate()
{
  QString value = text();
  if (value.isEmpty())
    {
      return 0;
    }
  else
    {
      return value.toFloat();
    }
}
void LineEdit_ThermostatRate::setRate(float rate)
{
  setText(QString::number(rate, 'f', accuracy));
}
void LineEdit_ThermostatRate::slot_thermostatRateLineEditFinished()
{
  if (text().isEmpty())
    {
      setText(QString::number(0));
      return;
    }
}
int LineEdit_ThermostatRate::getAccuracy()
{
  return accuracy;
}
void LineEdit_ThermostatRate::setAccuracy(int accuracy)
{
  this->accuracy = accuracy;
}
